<template> 
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>
                <el-button
                        style="float:right"
                        type="primary"
                        @click="searchAdminList()"
                        size="small">
                    查询搜索
                </el-button>
                <el-button
                        style="float:right;margin-right: 15px"
                        @click="handleResetSearch()"
                        size="small">
                    重置
                </el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="岗位编码：">
                        <el-input v-model="listQuery.postCode" class="input-width"
                                  placeholder="请输入岗位编码"></el-input>
                    </el-form-item>
                    <el-form-item label="岗位名称：">
                        <el-input v-model="listQuery.postName" class="input-width"
                                  placeholder="请输入岗位名称"></el-input>
                    </el-form-item>
                    <el-form-item label="状态：">
                        <el-select v-model="listQuery.status" class="input-width" placeholder="全部" clearable>
                            <el-option v-for="item in statusOptions"
                                       :key="item.value"
                                       :label="item.label"
                                       :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
            <el-button
                    class="btn-add"
                    @click="addAdmin()"
                    size="mini">
                添加
            </el-button>
        </el-card>
        <div class="table-container">
            <el-table ref="adminTable"
                      :data="list"
                      style="width: 100%"
                      @selection-change="handleSelectionChange"
                      v-loading="listLoading"
                      border>
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column label="岗位ID" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.postId}}</template>
                </el-table-column>
                <el-table-column label="岗位编码" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.postCode}}</template>
                </el-table-column>
                <el-table-column label="岗位名称" align="center">
                    <template slot-scope="scope">{{scope.row.postName}}</template>
                </el-table-column>
                <el-table-column label="岗位排序" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.postSort}}</template>
                </el-table-column>
                <el-table-column label="状态" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.status|formatStatus}}</template>
                </el-table-column>
                <el-table-column label="操作" width="250" align="center">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleUpdate(scope.$index, scope.row)">修改
                        </el-button>
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="pagination-container">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    layout="total, sizes,prev, pager, next,jumper"
                    :page-size="listQuery.pageSize"
                    :page-sizes="[5,10,15]"
                    :current-page.sync="listQuery.pageNum"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    import {formatDate} from '@/utils/date';
    import {listPost, delPost} from '@/api/sys/post'

    export default {
        name: 'adminList',
        data() {
            return {
                statusOptions: [
                    {
                        label: '正常',
                        value: 0
                    },
                    {
                        label: '禁用',
                        value: 1
                    }
                ],
                operateType: null,
                listQuery: {
                    keyword: null,
                    pageNum: 1,
                    pageSize: 10
                },
                list: null,
                total: null,
                listLoading: true,
                multipleSelection: []
            }
        },
        created() {
            this.getList();
        },
        filters: {
            formatStatus(status) {
                if (status === "0") {
                    return "正常"
                }
                if (status === "1") {
                    return "停用"
                }
            },
        },
        methods: {
            getList() {
                this.listLoading = true;
                listPost(this.listQuery).then(response => {
                    this.listLoading = false;
                    this.list = response.data.records;
                    this.total = response.data.total;
                    this.totalPage = response.data.pages;
                    this.pageSize = response.data.size;
                });
            },
            handleSizeChange(val) {
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.listQuery.pageNum = val;
                this.getList();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 修改
            handleUpdate(index, row) {
                this.$router.push({path: '/sys/updatePost', query: {id: row.postId}})
            },
            // 单个删除
            handleDelete(index, row) {
                this.$confirm('是否要删除该记录', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // var postIds = [];
                    // postIds.push(row.id)
                    // console.log("row.id")
                    delPost(row.postId).then(response => {
                        this.$message({
                            message: '删除成功',
                            type: 'success',
                            duration: 1000
                        });
                        this.getList();
                    });
                });
            },
            // 搜索列表
            searchAdminList() {
                this.listQuery.pageNum = 1;
                this.getList();
            },
            handleResetSearch() {
                this.listQuery = {}
            },
            // 添加
            addAdmin() {
                this.$router.push({path: '/sys/addPost'})
            }
        }
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>


</style>


